package com.share.device.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.share.common.log.annotation.Log;
import com.share.common.log.enums.BusinessType;
import com.share.common.security.annotation.RequiresPermissions;
import com.share.device.domain.CabinetSlot;
import com.share.device.service.ICabinetSlotService;
import com.share.common.core.web.controller.BaseController;
import com.share.common.core.web.domain.AjaxResult;
import com.share.common.core.utils.poi.ExcelUtil;
import com.share.common.core.web.page.TableDataInfo;

/**
 * 柜机插槽
 * 
 * @author
 * @date 2025-06-25
 */
@Tag(name = "柜机插槽")
@RestController
@RequestMapping("/slot")
public class CabinetSlotController extends BaseController
{
    @Autowired
    private ICabinetSlotService cabinetSlotService;

    /**
     * 查询柜机插槽列表
     */
    @RequiresPermissions("device:slot:list")
    @Operation(summary = "查询柜机插槽列表")
    @GetMapping("/list")
    public TableDataInfo list(CabinetSlot cabinetSlot)
    {
        startPage();
        List<CabinetSlot> list = cabinetSlotService.selectCabinetSlotList(cabinetSlot);
        return getDataTable(list);
    }

    /**
     * 导出柜机插槽列表
     */
    @RequiresPermissions("device:slot:export")
    @Operation(summary = "导出柜机插槽列表")
    @Log(title = "柜机插槽", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CabinetSlot cabinetSlot)
    {
        List<CabinetSlot> list = cabinetSlotService.selectCabinetSlotList(cabinetSlot);
        ExcelUtil<CabinetSlot> util = new ExcelUtil<CabinetSlot>(CabinetSlot.class);
        util.exportExcel(response, list, "柜机插槽数据");
    }

    /**
     * 获取柜机插槽详细信息
     */
    @RequiresPermissions("device:slot:query")
    @Operation(summary = "获取柜机插槽详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cabinetSlotService.selectCabinetSlotById(id));
    }

    /**
     * 新增柜机插槽
     */
    @RequiresPermissions("device:slot:add")
    @Operation(summary = "新增柜机插槽")
    @Log(title = "柜机插槽", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CabinetSlot cabinetSlot)
    {
        return toAjax(cabinetSlotService.insertCabinetSlot(cabinetSlot));
    }

    /**
     * 修改柜机插槽
     */
    @RequiresPermissions("device:slot:edit")
    @Operation(summary = "修改柜机插槽")
    @Log(title = "柜机插槽", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CabinetSlot cabinetSlot)
    {
        return toAjax(cabinetSlotService.updateCabinetSlot(cabinetSlot));
    }

    /**
     * 删除柜机插槽
     */
    @RequiresPermissions("device:slot:remove")
    @Operation(summary = "删除柜机插槽")
    @Log(title = "柜机插槽", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cabinetSlotService.deleteCabinetSlotByIds(ids));
    }
}
